<template>
  <div class="container header">
    <My-header title="客户资料">
      <!-- <span class="right" @click="refresh()">刷新</span> -->
    </My-header>
    <div class="content">
      <ul class="todo-list">
        <li v-for="item of clientList" :key="item.cid" >
          <div >
            <p class="no"><span class="span">{{item.cname}}</span>
              <span class="pos_a" @click="godetail(item.cname,item.cid)">
                查看详情
              </span>
            </p>
            <div class="info" >
              <p>联系人：{{item.lxr}} </p>
              <p>
                <span >电话：{{item.tel}} </span>
                <span class="text">{{item.ctname}}</span>
              </p>
              <p>地址：{{item.address}} </p>
            </div>
          </div>
          <!-- <div class="menu ui_border_t">
            <span class="red float_l">￥: {{item.totalm}}</span>
            <span @click="orderDetail(item.orderid)" class="btn-small">确认送货</span>
          </div> -->
        </li>
       
      </ul>
       <div class="no-more" v-if="clientList.length === 0 && !isLoading && isLoaded">
        暂无数据
      </div>
      <div @click="getClient()" class="add-more" v-if="clientList.length > 0 && !isLoading && !isLoaded">点击加载更多...</div>
      <div class="no-more" v-if="clientList.length > 0 && !isLoading && isLoaded">没有更多了</div>
      <Spinner v-if="isLoading"></Spinner> 
    </div>
    <Tabnav name="nav" />
  </div>
</template>

<script>
import Tabnav from "@/components/Tabnav.vue";
import MyHeader from "@/components/MyHeader.vue";
import Spinner from "@/components/Spinner.vue";
import { mapState } from "vuex";
import axios from "axios";

export default {
  name: "client",
  components: {
    MyHeader,
    Tabnav,
    Spinner
  },
  data(){
    return{
      clientList: [],
      pageNo:0,
      // 是否在加载中
      isLoading: false,
      // 是否加载完成
      isLoaded: false
     
    }
    

  },
  computed: {
    ...mapState([ "userInfo" ])
  },
  mounted(){
    this.getClient();
  },
  methods: {
    godetail(name,id) {
      this.$router.push({ name: "clientDetail", params: { name,id } });
    },
    getClient() {
      this.isLoading = true;
      axios
        .get("/sellgl/sellgl!selCust.action", {
          params: {
            sid: this.userInfo.id
            
          }
        })
        .then(response => {
          this.$loading.close();
          this.clientList = response.data.list;
         
          this.pageNo++;
          this.isLoading = false;
          this.isLoaded = response.data.state === 1;
        })
        .catch(function(error) {
          window.console.log(error);
        });
    }
  }
  
};
</script>

<style lang="scss">
@import "../assets/basic.scss";

.todo-list {
  padding: 0.5rem;
  li {
    background: #fff;
    margin-bottom: 0.5rem;
    .info {
      padding-right: 1rem;
      position: relative;
      padding: 0.8rem;
      border-bottom: 0.05rem solid #eee;
      // &::after {
      //   font-family: "iconfont";
      //   content: "\e622";
      //   position: absolute;
      //   right: 0;
      //   top: 1.8rem;
      //   transform: rotate(180deg);
      //   color: #999;
      // }
      .text {
        float: right;
        color: #ffffff;
        // margin-right: 0.5rem;
        border: 0.1rem solid #eee;
        border-radius: 1rem;
        padding: 0 0.3rem;
        background: #FFC107;
      }
      span.icon {
        font-size: 1.6rem;

        color: red;
      }
    }
    .menu {
      position: relative;
      text-align: right;
      // margin-top: 0.5rem;
      // padding-top: 0.5rem;
      padding: 0.5rem;
    }
    p {
      line-height: 1.5rem;
    }
    .no {
      position: relative;
      border-bottom: 0.05rem solid #eee;
      color: #aaa;
      padding: 0.5rem 0;
      border-left: 0.3rem solid #3cc347;
      background: rgba(238, 238, 238, 0.3);
      // &::after {
      //   font-family: "iconfont";
      //   content: "\e622";
      //   position: absolute;
      //   right: 0;
      //   transform: rotate(180deg);
      //   color: #999;
      // }
      span {
        margin-left: 0.5rem;
      }
    }
  }
}

.add-more,
.no-more {
  text-align: center;
  padding-bottom: 1rem;
}
.btn-small {
  background: $basicColor;
  color: #fff;
  padding: 0.3rem 0.5rem;
  border-radius: 0.2rem;
  font-size: 0.8rem;
  display: inline-block;
  &:active {
    background: $basicColor-dark;
  }
}
.red {
  font-weight: bold;
  color: $second-color;
  float: right;
}
.float_l {
  float: left;
}
.float_r {
  float: right;

}
.pos_a{
  position: absolute;
  right: 0.2rem;
}

</style>
